package com.example.hfweather.ui.detail

import com.example.hfweather.base.BasePresenter
import com.qweather.sdk.response.indices.IndicesDailyResponse

class WeatherDetailPresenter(val mView: WeatherDetailView, val mInteractor: WeatherDetailInteractor):
    BasePresenter<WeatherDetailView,
            WeatherDetailInteractor>(mView, mInteractor),
    WeatherDetailInteractor.Get3DayWeatherCallBack,
        WeatherDetailInteractor.GetTodayIndicesCallBack

{

    private var mCityName = ""
    private var mLatitude = ""
    private var mLongitude = ""

    /**
     * 设置城市名称
     */
    fun setCityName(cityName: String) {
        mCityName = cityName
    }

    /**
     * 设置经纬度
     */
    fun setLocation(latitude: String, longitude: String) {
        mLatitude = latitude
        mLongitude = longitude
    }

    /**
     *  获取3天天气
     *  参数：经纬度
     */
    fun get3DayWeather() {
        mInteractor.get3DayWeather(mLatitude, mLongitude, this)
    }
    /**
     * 获取今天的生活指数
     * 参数：经纬度
     */
    fun getTodayIndices() {
        mInteractor.getTodayIndices(mLatitude, mLongitude, this)
    }

    /**
     * 获取3天天气成功
     */
    override fun get3DayWeatherSuccess(weather: com.qweather.sdk.response.weather.WeatherDailyResponse) {
        weather.run {
            // 今日天气
            mView.refreshTodayDataSuccess(weather.daily[0])
            //其他两天
            mView.refreshOther2DaysSuccess(weather.daily[1], weather.daily[2])


        }
    }

    /**
     * 获取3天天气失败
     */
    override fun get3DayWeatherFailure(error: kotlin.String) {
        mView.refreshTodayDataFail(error)
        mView.refreshOther2DaysFail(error)
    }

    /**
     *  获取今天的生活指数成功
     */
    override fun getTodayIndicesSuccess(weather: com.qweather.sdk.response.indices.IndicesDailyResponse) {
        weather.run {
            mView.refreshTodayIndicesSuccess(weather)
        }
    }

    /**
     *  获取今天的生活指数失败
     */
    override fun getTodayIndicesFailure(error: kotlin.String) {
        mView.refreshTodayIndicesFailure(error)
    }

}